New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DuplicateRecordFields without ambiguous field access #366
DuplicateRecordFields without ambiguous field access #366
Conversation
I agree with the proposed direction of travel. The way I see it, there are two approaches to name overloading:
Haskell normally uses (2), but in rare cases ends up using (1), one such case being |
I feel a bit silly bringing this up, but might you rename the proposal something like
Since you define "field selector occurrence" and "field update occurrence", and the proposal applies to both, I think it's confusing to title it with the word "selector". I agree the "Type-driven name resolution" that's done is bad. I'm not sure "Class-based polymorphism" is good, but I remain a little hopeful the "Name-driven" resolution I went for in #310 becomes viable after all. I like this proposal because it just pushes us away from type-driven resolution, and doesn't bias one alternative over another. |
Regarding type-directed name resolution, my feeling is that it is in principle a useful approach, particularly in languages that are heavily slanted towards bidirectional type-checking (e.g. Idris, Agda). That is, I think TDNR done right can work well. But the use in (A good bidirectional/TDNR story for record selectors really needs dot-notation, because then you can infer the type of the record being accessed and use that to disambiguate the selector. But with
@Ericson2314 thanks, that's a good point. (I originally wrote the proposal for selectors, then decided to add updates, and of course I forgot to change the title. 🤦) I've updated the PR. |
I'm strongly in favour of this proposal. The current design is an egregious hack; I don't think it would every have got past this committee! Moreover, it has a pretty significant implementation cost; that would be OK if it were in service of a principled goal, but it isn't. Let's tidy this up. |
I'm also in strong support of this proposal. Indeed, I would advocate for a shorter, more abrupt transition period. Maybe we warn for a release, but then just rip out the existing machinery. Any change to code is fully backward compatible. Users could easily convince me that a slower transition is better, but I don't think we designers should assume that users need the slower transition. |
I'm not formally a part of the approval process, but I did want to chime in with a strong +1 in favor of this proposal. |
@goldfirere the reaction to this proposal is making me agree we should rip it out ASAP. So default to (Incidentally, this gist from @chrisdone shows how the module system can be used nicely to avoid field occurrence ambiguity in modules other than the defining module. I half wonder if we should allow modules to import themselves qualified and with an explicit import list, so this trick would work in the defining module as well...) |
Yes, I support the more rapid removal @adamgundry proposed. |
cute! Isn't there a more general feature lurking here, not specific to ambiguous record field names? (They merely bite the worst.) For example I've seen loose talk about multi-module modules: that is, one source file with multiple There are for example StackOverflow questions asking why you can't use duplicate names for data constructors, especially for enumerated types:
mmm that seems heavy machinery. Would something like this be more succinct (but using the same name prefixing under the covers)
in which if the (hmm hmm I used |
@AntC2 yes, local modules would be another way to be able to disambiguate field occurrences, and there might indeed be some merit in having datatype declarations imply local modules. FWIW, being able to refer to the enclosing module with a different prefix and an explicit import list has come up as desirable before (https://gitlab.haskell.org/ghc/ghc/-/issues/15432). But in any case this is out of scope of the current proposal. So far the only dissatisfaction I've seen with this proposal is a single 👎 from @klapaucius. Would you be willing to elaborate? I've thrown together a rough implementation of the new warning at https://gitlab.haskell.org/ghc/ghc/-/commit/abf0fb3138bd05a94fe69fb887cf308e51d3a7d4 ... anyone fancy bikeshedding the warning text?
|
I prefer that existing features aren't removed unless they are really problematic. Such removals induce unnecessary anxiety about extensions and I'm not looking forward to discussions with my colleagues what we shouldn't use some extensions because "they can be removed at any moment just like TDNR in DuplicateRecordFields". |
@nomeata I believe this proposal is ready for review. From the discussion:
@klapaucius thanks for the feedback. I do acknowledge that breaking changes are always painful, but if we don't make them we are stuck with dubious design decisions forever, and here I think the consensus is that this feature is one we could do without. I've added a line to the "Costs and Drawbacks" section, and added a new section documenting migration strategies for fixing existing code. |
@nomeata ping; I would like to submit this proposal for committee review. |
Thanks for the ping! |
I'm in favour of this proposal for several reasons, all of which have already been given above. I think the current behaviour is unintuitive, and this proposal's explicit presentation of the rules (under which the current TDNR works) is the first time I've really thought about them beyond hand-waving or trial and error. I'm therefore going to recommend that we accept this, pending committee review. |
Hey! We've discussed this as a committee, and we agree that it should go ahead. This proposal will now be marked as accepted, and @nomeata will merge it in for us. Thanks for submitting the proposal! |
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
Fixes #18966. Adds a new warning -Wambiguous-fields for uses of field selectors or record updates that will be rejected in the future, when the DuplicateRecordFields extension is simplified per ghc-proposals/ghc-proposals#366.
This proposal mentions |
The proposal has been accepted; the following discussion is mostly of historic interest.
This proposal addresses an unsatisfactory aspect of
DuplicateRecordFields
, namely the unclear rules around when a field selector or update will be accepted, by entirely removing the type-directed name resolution aspect. This proposal is more restrictive than the previous (dormant) simplification proposal #84, allowing fewer programs, but correspondingly simpler. The proposal is similar to and reuses parts of #84, but I decided to open a new proposal as the suggested simplification here is more radical.Rendered.